/**
 * ajax 加强服务
 */
define(function () {
    var getContext = function (serviceUrl) {
        var pathname = document.location.pathname;
        return "/" + pathname.split("/")[1] + serviceUrl;
    };

    /**
     * ajax post服务
     * @param serviceUrl
     * @param data
     * @param callback
     * @returns {*}
     * @private
     */
    var _getService = function (serviceUrl, data, callback) {
        return _service(serviceUrl, data, "get", callback);
    };

    /**
     * ajax get服务
     * @param serviceUrl
     * @param data
     * @param callback 回调函数
     * @returns {*}
     * @private
     */
    var _postService = function (serviceUrl, data, callback) {
        return _service(serviceUrl, data, "post", callback);
    };

    /**
     * ajax服务
     * @param serviceUrl
     * @param data
     * @param type
     * @param callback 回调函数
     * @returns {*}
     * @private
     */
    var _service = function (serviceUrl, data, type, callback) {
        return $.ajax({
            url: getContext(serviceUrl),
            type: type,
            contentType: "application/json;charset=utf-8;",
            data: JSON.stringify(data),
            success: callback
        });
    };

    return {
        service: _service,
        getService: _getService,
        postService: _postService
    }
});